package cc.utils;

import java.io.File;
import java.io.IOException;

import java.lang.*;

import java.util.HashMap;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.Attributes;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXNotSupportedException;
import org.xml.sax.SAXParseException;
import org.xml.sax.XMLReader;
import org.xml.sax.ext.LexicalHandler;
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.helpers.ParserAdapter;
import org.xml.sax.helpers.XMLReaderFactory;


public class ParserHandler {
    String filenames[] = null;

    public String[] ReturnFileName(String configDir) throws Exception {
        MessageParser obj = new MessageParser();
        try {
            SAXParserFactory spf = SAXParserFactory.newInstance();
            SAXParser parser = spf.newSAXParser();
            parser.parse(new File(configDir + "LanguageConfig.xml"), obj);
            
        } catch (SAXException e) {
            System.err.println(e.getMessage());
        }
        this.filenames = obj.fileName.split(",");
        
        return obj.langName.split(",");
    }

    public HashMap<String, String>[] ReturnMessage(String configDir) throws Exception {
        
        
        int len = filenames.length;
        HashMap<String, String>[] hashId = new HashMap<String, String>[len];
        int i =0;
        for (;i<len;i++){
            
        
        LanguageParser obj = new LanguageParser();
        try {
            SAXParserFactory spf = SAXParserFactory.newInstance();
            SAXParser parser = spf.newSAXParser();
            parser.parse(new File(configDir  + filenames[i]), obj);
        } catch (SAXException e) {
            System.err.println(e.getMessage());
        }

        hashId[i] = obj.hashMap;
        
        }
        
        return hashId;
    }
}

